var g, app = getApp(), page = app.page, request = app.util.request, route = app.route, toast = app.toast;

function getMLawArticleType() {
    request({
        url: "MLawArticleType",
        data: {
            user_id: app.userInfo.id || wx.getStorageSync("userInfo").id
        },
        showLoading: !1,
        success: function(t) {
            wx.stopPullDownRefresh(), g.setData({
                typeList: t
            });
        }
    });
}

function getMLawArticle() {
    request({
        url: "MLawArticle",
        data: {
            user_id: app.userInfo.id || wx.getStorageSync("userInfo").id
        },
        showLoading: !1,
        success: function(t) {
            wx.stopPullDownRefresh(), g.setData({
                newList: t
            });
        }
    });
}

page({
    data: {
        cur: 0,
        navs: [ {
            title: "文章",
            id: 0
        }, {
            title: "分类",
            id: 1
        } ],
        no_data: app.srcRoot + "no_data.png"
    },
    onLoad: function(t) {
        g = this, getMLawArticleType();
    },
    onPullDownRefresh: function() {
        0 == g.data.cur && getMLawArticle(), 1 == g.data.cur && getMLawArticleType();
    },
    onShow: function() {
        0 == g.data.cur && getMLawArticle(), 1 == g.data.cur && getMLawArticleType();
    },
    tabSelect: function(t) {
        t = parseInt(t.currentTarget.dataset.id || 0), g.setData({
            cur: t
        }), 0 == t && getMLawArticle(), 1 == t && getMLawArticleType();
    },
    toDo: function(t) {
        var e = (t = t.currentTarget.dataset).type, a = t.data, r = t.url;
        switch (e) {
          case "del":
            request({
                url: r,
                data: {
                    id: a.id
                },
                success: function(t) {
                    g.onShow(), toast("删除" + (1 == t ? "成功" : "失败"));
                }
            });
            break;

          case "edit":
            if ("l_news_edit" == r && g.data.typeList.length < 1) return toast("请先添加文章分类");
            app.item = a, route({
                type: "navigate",
                url: r
            });
        }
    }
});